package com.lc202310;

import java.util.PriorityQueue;

/**
 * Description:
 *
 * @Create 2023/10/28 21:59
 * @Version 1.0
 */
public class Solution2558 {
    public long pickGifts(int[] gifts, int k) {
        PriorityQueue<Integer> queue = new PriorityQueue<>((a, b) -> b - a);
        for (int gift : gifts) {
            queue.offer(gift);
        }
        while (k > 0) {
            k--;
            int poll = queue.poll();
            queue.offer((int) Math.sqrt(poll));
            if (poll == 1 || poll == 0) {
                break;
            }
        }
        long res = 0;
        while (!queue.isEmpty()) {
            res += queue.poll();
        }
        return res;
    }
}
